$(function () {
    $("#student").click(function () {
        $.post("/login", {
            option: "student",
            name: $("#name")[0].value,
            password: $("#password")[0].value
        }, function (result) {
            console.log(result);
            if (result["error"] != null) {
                alert(result["error"])
            } else {
                localStorage.clear();
                window.location.href = "/exam"
            }
        })
    });
    $("#admin").click(function () {
        $.post("/login", {
            option: "admin",
            name: $("#name")[0].value,
            password: $("#password")[0].value
        }, function (result) {
            console.log(result);
            if (result["error"] != null) {
                alert(result["error"])
            } else {
                window.location.href = "/manager"
            }
        })
    });

    $("#update").click(function () {
        console.log($("#option1").parent().hasClass("active"));
        console.log($("#option2").parent().hasClass("active"));
        if ($("#option1").parent().hasClass("active") === true) {
            $("#sex").val("1");
            console.log("sex is 1")
        } else {
            $("#sex").val("2");
            console.log("sex is 2")
        }
        $("#updatenews").ajaxSubmit(function (data) {
            console.log(data);
            if (data["error"] === undefined && data["row"] === 1) {
                alert("注册成功!");
                window.location.reload()
            } else {
                alert("注册失败!")
            }
        });
    })
});